package graph.group.zhangtao.guider.homepage.adapters;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import graph.group.zhangtao.guider.R;
import graph.group.zhangtao.guider.homepage.content.SearchItem;

/**
 * Created by T5 on 2018/3/25.
 */

public class SearchItemAdapter extends ArrayAdapter<SearchItem> {

    private int resourceId;

    public SearchItemAdapter(@NonNull Context context, int resource, int textViewResourceId, @NonNull List<SearchItem> objects) {
        super(context, resource, textViewResourceId, objects);
        resourceId = resource;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        SearchItem searchItem = getItem(position);
        View view = LayoutInflater.from(getContext()).inflate(resourceId,parent,false);

        ImageView rootImage = view.findViewById(R.id.root_desc_image);
        TextView rootTitle = view.findViewById(R.id.tv_search_title);
        TextView rootBriefDesc = view.findViewById(R.id.tv_root_brief_desc);
        TextView rootEncourageTimes = view.findViewById(R.id.tv_root_encourage_times);

        rootEncourageTimes.setText(searchItem.getEncourageTimes());
        rootImage.setImageResource(searchItem.getImageId());
        rootTitle.setText(searchItem.getSearchTitle());
        rootBriefDesc.setText(searchItem.getResultBriefDesc());
        return view;
    }
}
